#include <bits/stdc++.h>
using namespace std;

int m;
int p[100001]={};
int get_flag1(int l1, int l2)
{
    for (int j=1;j<=m;++j)
        if (l1<=p[j]&&p[j]<=l2)
            return j;
    return 0;
}
void ma()
{
    int n,m,L,v;
    cin>>n>>m>>L>>v;
    int a[n+1][3]={{}};
    for (int i=1;i<=n;++i)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    int p[m+1]={};
    for (int i=1;i<=m;++i)
        cin>>p[i];
    int cnt=0;
    for (int i=1;i<=n;++i){
        if (a[i][2]>0)
            if (p[m]>=a[i][0]){
                if (a[i][1]>v)
                    cnt++;
                else {
                    double l=double(pow(v,2)-pow(a[i][1],2))/double(2*a[i][2]);
                    if (l+a[i][0]<p[m]) {
                        cnt++;
                    }
                }
            }
        if (a[i][2]==0)
            if (p[m]>=a[i][0])
                if (a[i][1]>v){
                    cnt++;
                }
        if (a[i][2]<0){
            double l1=double(0-pow(a[i][1],2))/double(2*a[i][2]);
            int flag = get_flag1(a[i][0],a[i][0]+l1);
            if (flag)
                if (a[i][1]>v){
                    double l2=double(pow(v,2)-pow(a[i][1],2))/double(2*a[i][2]);
                    if (l2+a[i][0]>p[flag]){
                        cnt++;
                    }
                }
        }
    }
    if (cnt)
        cout<<cnt<<' '<<m-1<<endl;
    else
        cout << cnt << ' ' << m << endl;
}

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    for (int i=1;i<=t;++i)
        ma();
    return 0;
}